/**
 * AprsSymbols.java
 * 
 */

package com.google.code.netcheckin.app;

import java.util.HashMap;
import java.awt.Image;
import java.awt.image.CropImageFilter;
import java.awt.image.FilteredImageSource;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

/**
 * 
 * @author cshields
 */
public class AprsSymbols extends JFrame {
    
    public static final int SYMBOL_WIDTH = 20;
    public static final int SYMBOL_HEIGHT = 20;
    
    private HashMap symbolToIndexMap;
    private ImageIcon symbols1;
    private ImageIcon symbols2;
    private Image workingImage1;
    private Image workingImage2;
    private Image image;
    
    private Integer[] indexArray = {0, 1, 2, 3, 4};
    private String[] descriptionArray = {"House",
                                         "RedCross",
                                         "Car",
                                         "Campgrnd",
                                         "EOC"};
    private String[] symbolArray = {"/-",
                                    "/+",
                                    "/>",
                                    "/;",
                                    "/o"};
    
    private ImageIcon[] iconArray;
    
    public AprsSymbols() {
        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(com.google.code.netcheckin.app.NetCheckInApp.class).getContext().getResourceMap(AprsSymbols.class);

        iconArray = new ImageIcon[indexArray.length];
        
        symbols1 = resourceMap.getImageIcon("symbols1.icon");
        symbols2 = resourceMap.getImageIcon("symbols2.icon");
        workingImage1 = symbols1.getImage();
        workingImage2 = symbols2.getImage();
        
        initializeSymbolToIndexMap();
        
        initializeImages();
    }
    
    public void initializeSymbolToIndexMap() {
        symbolToIndexMap = new HashMap();
        
        for (Integer i : indexArray) {
            symbolToIndexMap.put(symbolArray[i], i);
        }
    }
    
    public void initializeImages() {
        // House
        image = createImage(new FilteredImageSource(workingImage1.getSource(),
                new CropImageFilter(253, 1, 20, 20)));
        iconArray[0] = new ImageIcon(image);
        
        // RedCross
        image = createImage(new FilteredImageSource(workingImage1.getSource(),
                new CropImageFilter(211, 1, 20, 20)));
        iconArray[1] = new ImageIcon(image);
        
        // Car
        image = createImage(new FilteredImageSource(workingImage1.getSource(),
                new CropImageFilter(274, 22, 20, 20)));
        iconArray[2] = new ImageIcon(image);
        
        // Campground
        image = createImage(new FilteredImageSource(workingImage1.getSource(),
                new CropImageFilter(211, 22, 20, 20)));
        iconArray[3] = new ImageIcon(image);
        
        // EOC
        image = createImage(new FilteredImageSource(workingImage1.getSource(),
                new CropImageFilter(295, 85, 20, 20)));
        iconArray[4] = new ImageIcon(image);
    }
    
    public ImageIcon getIcon(int index) {
        if (index >= 0) {
            return iconArray[index];
        }
        return null;
    }
    
    public String getDescription(int index) {
        return descriptionArray[index];
    }
    
    public String getSymbol(int index) {
        return symbolArray[index];
    }
    
    public Integer getIndexOfSymbol(String symbol) {
        Object result = symbolToIndexMap.get(symbol);
        if (result == null) {
            return 0;
        }
        return (Integer) result;
    }
    
    public Integer[] getIndexArray() {
        return indexArray;
    }
    
    public String[] getSymbols() {
        return symbolArray;
    }
    
    public ImageIcon[] getIcons() {
        return iconArray;
    }
}